import handler from "./index"

let reducer = (state = {...handler.state}, action: {type: string, val: number}) => {
    let newState = JSON.parse(JSON.stringify(state))
    // switch (action.type) {
    //     case handler.add1:
    //         handler.actions[handler.add1](newState, action)
    //         break;
    //     case handler.add2:
    //         handler.actions[handler.add2](newState, action)
    //         break;
    //     default:
    //         break
    // }
    for(let key in handler.actionNames){
        if(action.type===handler.actionNames[key]){
            handler.actions[handler.actionNames[key]](newState,action)
            break
        }
    }
    return newState
}

export default reducer